/*     */ package com.zimbra.qa.unittest.prov.soap;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.DomainBy;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.SoapTransport;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.qa.unittest.TestUtil;
/*     */ import org.junit.Assert;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class GalTestUtil
/*     */ {
/*     */   static final String GAL_SYNC_ACCOUNT_NAME = "galsync";
/*     */   
/*     */   public static enum GSAType
/*     */   {
/*  35 */     zimbra, 
/*  36 */     external, 
/*  37 */     both;
/*     */     
/*     */     private GSAType() {}
/*     */   }
/*     */   
/*  42 */   public static void disableGalSyncAccount(Provisioning prov, String domainName) throws Exception { Domain domain = prov.get(Key.DomainBy.name, domainName);
/*     */     
/*  44 */     String[] galSyncAcctIds = domain.getGalAccountId();
/*  45 */     for (String galSyncAcctId : galSyncAcctIds) {
/*  46 */       prov.deleteAccount(galSyncAcctId);
/*     */     }
/*     */     
/*  49 */     domain.unsetGalAccountId();
/*     */   }
/*     */   
/*     */   public static void enableGalSyncAccount(Provisioning prov, String domainName)
/*     */     throws Exception
/*     */   {
/*  55 */     enableGalSyncAccount(prov, domainName, (String)null);
/*     */   }
/*     */   
/*     */   public static void enableGalSyncAccount(Provisioning prov, String domainName, String galSyncAcctLocalpart)
/*     */     throws Exception
/*     */   {
/*  61 */     enableGalSyncAccount(prov, domainName, galSyncAcctLocalpart, GSAType.zimbra);
/*     */   }
/*     */   
/*     */   public static void enableGalSyncAccount(Provisioning prov, String domainName, GSAType type) throws Exception
/*     */   {
/*  66 */     enableGalSyncAccount(prov, domainName, (String)null, type);
/*     */   }
/*     */   
/*     */   public static void enableGalSyncAccount(Provisioning prov, String domainName, String galSyncAcctLocalpart, GSAType type)
/*     */     throws Exception
/*     */   {
/*  72 */     Domain domain = prov.get(Key.DomainBy.name, domainName);
/*  73 */     String[] galSyncAcctIds = domain.getGalAccountId();
/*  74 */     if (galSyncAcctIds.length > 0)
/*     */     {
/*  76 */       return;
/*     */     }
/*  78 */     String localpart = galSyncAcctLocalpart == null ? "galsync" : galSyncAcctLocalpart;
/*     */     
/*     */ 
/*  81 */     createAndSyncGalSyncAccount(TestUtil.getAddress(localpart, domainName), domainName, type);
/*     */   }
/*     */   
/*     */ 
/*     */   static void createAndSyncGalSyncAccount(String galSyncAcctName, String domainName, GSAType type)
/*     */     throws Exception
/*     */   {
/*     */     String folderName;
/*     */     
/*     */     String dataSourceName;
/*     */     String dataSourceType;
/*     */     String folderName;
/*  93 */     if ((type == GSAType.zimbra) || (type == GSAType.both)) {
/*  94 */       String dataSourceName = "zimbra";
/*  95 */       String dataSourceType = "zimbra";
/*  96 */       folderName = "zimbra-gal-contacts";
/*     */     } else {
/*  98 */       dataSourceName = "external";
/*  99 */       dataSourceType = "ldap";
/* 100 */       folderName = "external-gal-contacts";
/*     */     }
/*     */     
/*     */ 
/* 104 */     SoapTransport transport = TestUtil.getAdminSoapTransport();
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 109 */     String gsaZimbraId = createGalSyncAccountOrDataSource(transport, galSyncAcctName, domainName, dataSourceName, dataSourceType, folderName);
/*     */     
/*     */ 
/*     */ 
/* 113 */     syncGASDataSource(transport, gsaZimbraId, dataSourceName);
/*     */     
/* 115 */     if (type == GSAType.both) {
/* 116 */       dataSourceName = "external";
/* 117 */       dataSourceType = "ldap";
/* 118 */       folderName = "external-gal-contacts";
/* 119 */       createGalSyncAccountOrDataSource(transport, galSyncAcctName, domainName, dataSourceName, dataSourceType, folderName);
/*     */       
/*     */ 
/* 122 */       syncGASDataSource(transport, gsaZimbraId, dataSourceName);
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 128 */     Element eReIndex = Element.create(transport.getRequestProtocol(), AdminConstants.REINDEX_REQUEST);
/*     */     
/* 130 */     eReIndex.addAttribute("action", "start");
/* 131 */     Element eMbox = eReIndex.addElement("mbox");
/* 132 */     eMbox.addAttribute("id", gsaZimbraId);
/* 133 */     transport.invoke(eReIndex);
/*     */     
/*     */ 
/* 136 */     Thread.sleep(2000L);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   static String createGalSyncAccountOrDataSource(SoapTransport transport, String galSyncAcctName, String domainName, String dataSourceName, String dataSourceType, String folderName)
/*     */     throws Exception
/*     */   {
/* 144 */     Element eCreateReq = Element.create(transport.getRequestProtocol(), AdminConstants.CREATE_GAL_SYNC_ACCOUNT_REQUEST);
/*     */     
/*     */ 
/* 147 */     eCreateReq.addAttribute("name", dataSourceName);
/* 148 */     eCreateReq.addAttribute("domain", domainName);
/* 149 */     eCreateReq.addAttribute("type", dataSourceType);
/* 150 */     eCreateReq.addAttribute("folder", folderName);
/*     */     
/* 152 */     Element eAccount = eCreateReq.addElement("account");
/* 153 */     eAccount.addAttribute("by", Key.AccountBy.name.name());
/* 154 */     eAccount.setText(galSyncAcctName);
/*     */     
/* 156 */     Element response = transport.invoke(eCreateReq);
/*     */     
/* 158 */     eAccount = response.getElement("account");
/* 159 */     String name = eAccount.getAttribute("name");
/* 160 */     String id = eAccount.getAttribute("id");
/* 161 */     Assert.assertEquals(galSyncAcctName, name);
/*     */     
/* 163 */     return id;
/*     */   }
/*     */   
/*     */   static void syncGASDataSource(SoapTransport transport, String gsaZimbraId, String dataSourceName)
/*     */     throws Exception
/*     */   {
/* 169 */     Element eSyncReq = Element.create(transport.getRequestProtocol(), AdminConstants.SYNC_GAL_ACCOUNT_REQUEST);
/*     */     
/*     */ 
/* 172 */     Element eAccount = eSyncReq.addElement("account");
/* 173 */     eAccount.addAttribute("id", gsaZimbraId);
/*     */     
/* 175 */     Element eDataSource = eAccount.addElement("datasource");
/* 176 */     eDataSource.addAttribute("reset", "TRUE");
/* 177 */     eDataSource.addAttribute("by", Key.AccountBy.name.name());
/* 178 */     eDataSource.setText(dataSourceName);
/*     */     
/* 180 */     transport.invoke(eSyncReq);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/soap/GalTestUtil.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */